@echo off

echo.

rem
rem Ensure we have all required tools
rem

if not "%Wix%"=="" goto wixSet

rem Check default wix folder
if not exist "%ProgramFiles%\Windows Installer XML v3\bin\light.exe" goto wixWow64check
echo light.exe found in "%ProgramFiles%\Windows Installer XML v3\bin" folder
set Wix=%ProgramFiles%\Windows Installer XML v3
goto wixSet

:wixWow64check
if not exist "%ProgramFiles(x86)%\Windows Installer XML v3\bin\light.exe" goto errEnvVarWix
echo light.exe found in "%ProgramFiles(x86)%\Windows Installer XML v3\bin" folder
set Wix=%ProgramFiles(x86)%\Windows Installer XML v3

:wixSet

rem
rem Ready to build the setup.exe
rem

set ScoutSetupContent=%~dp0dist
set MsiFile=%~dp0ScoutSetup.msi

echo Wixing "%Wix%"

"%Wix%\bin\candle.exe" -ext WixNetFxExtension -sw1080 *.wxs
if not errorlevel 0 goto done
if errorlevel 1 goto done

"%Wix%\bin\light.exe"  -ext WixNetFxExtension *.wixobj -ext WixUIExtension -out "%MsiFile%" -cultures:en-us 
if not errorlevel 0 goto done
if errorlevel 1 goto done

rem Clean up
del *.wixobj

 MSIEXEC /i ScoutSetup.msi /l log.txt /passive

echo.
echo Done.
goto done

:errEnvVarWix
echo Please specify environment variable "Wix".
goto done

:done
cd "%~dp0"
pause